﻿
using System.Collections.Generic;
using System.Data;
using System;
using ZHDJ.WebPage;

namespace ZHDJ.MobileInterface
{
    public partial class UpdateMembersInfo : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MembersInfoEditOutParam result = new MembersInfoEditOutParam();
            MembersInfoEditInParam param = new MembersInfoEditInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MembersInfoEditInParam;
                if (string.IsNullOrEmpty(param.user_id) || string.IsNullOrEmpty(param.user_name) || string.IsNullOrEmpty(param.mobile))
                {
                    result.code = "0";
                    result.desc = "用户ID,用户名,手机号码不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (CommonUtils.IsDisableUsers(param.user_id))
                    {
                        result.code = "0";
                        result.desc = "用户状态有问题，请联系管理员";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (!InterfaceHelper.CheckLoginIDCountEx(param.user_id))
                    {
                        result.code = "0";
                        result.desc = "该用户ID不存在";

                        isFlag = false;
                    }
                }

                // 用户名改成用户姓名，这里不再需要验证
                //if (isFlag)
                //{
                //    if (!InterfaceHelper.UserNameIsAbleUpdate(param.user_id, param.user_name))
                //    {
                //        result.code = "0";
                //        result.desc = "该用户名已经存在";

                //        isFlag = false;
                //    }
                //}

                if(isFlag)
                {
                    //UpFileResult upResult = UpFileBusiness.Upload(Convert.FromBase64String(param.head_img), param.user_name + ".jpg", param.user_id, "");

                    string fileID = "";
                    //if (upResult.IsSuccess && !string.IsNullOrEmpty(upResult.FileID))
                    //{
                    //    fileID = upResult.FileID;
                    //}
                    param.head_img = "";
                    InterfaceHelper.UpdateMembersInfoNew(param, fileID);  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                param.head_img = "";
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            if (result.code == "1")
                param.head_img = ""; //照片内容太多，影响数据库性能

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-UpdateMembersInfo", SerializeHelper.JsonSerializer<MembersInfoEditInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MembersInfoEditInParam, MembersInfoEditOutParam>();
            else
                SafeProcessRequest<MembersInfoEditInParam, MembersInfoEditOutParam>();
        }
    }

    #region 请求参数
    public class MembersInfoEditInParam
    {
        /// <summary>
        ///	用户ID
        /// </summary>
        public string user_id
        { get; set; } 

        /// <summary>
        ///	用户名
        /// </summary>
        public string user_name
        { get; set; } 

        /// <summary>
        ///	头像 
        /// </summary>
        public string head_img
        { get; set; } 

        ///// <summary>
        /////	头像文件名 
        ///// </summary>
        //public string head_filename
        //{ get; set; } 

        /// <summary>
        ///	手机号 
        /// </summary>
        public string mobile
        { get; set; } 

        ///// <summary>
        /////	电子邮箱 
        ///// </summary>
        //public string email
        //{ get; set; } 

        ///// <summary>
        /////	QQ 
        ///// </summary>
        //public string qq
        //{ get; set; } 

        ///// <summary>
        /////	联系地址 
        ///// </summary>
        //public string contact_addr
        //{ get; set; }  
    }
    #endregion

    #region 结果参数
    public class MembersInfoEditOutParam
    {
        public MembersInfoEditOutParam()
        {
            code = "1";
            desc = "操作成功"; 
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; } 
    }  
    #endregion 
}